package com.taotao.manager.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.taotao.manager.service.ItemDescService;
import com.taotao.pojo.TbItemDesc;

@Controller
@RequestMapping("/item/desc")
public class ItemDescController {

	private static final Logger LOGGER = LoggerFactory.getLogger(ItemDescController.class);
	
	@Autowired
	private ItemDescService itemDescService;
	
	/**
	 * 根据商品ID查询商品描述
	 * <p>Title: queryByItemId</p>
	 * <p>Description: </p>
	 * @param id
	 * @return
	 */
	@RequestMapping(value="{itemId}",method = RequestMethod.GET)
	public ResponseEntity<TbItemDesc> queryByItemId(@PathVariable(value="itemId")long id) {
		try {
			TbItemDesc itemDesc = this.itemDescService.queryById(id);
			if(itemDesc == null) {
				return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
			}
			return ResponseEntity.ok(itemDesc);
		} catch(Exception e) {
			e.printStackTrace();
			LOGGER.error("查询商品描述失败，商品id="+id,e);
		}
		return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
	}
	
}
